﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entities;
namespace WCF_ListenMusic.Services.Module_Comment.User
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CommentService" in code, svc and config file together.
    public class CommentService : ICommentService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        #region ICommentService Members


        public bool InsertComment(Comment comment)
        {
            try
            {
                
                comment.CommentID = getMax_CommentID() + 1;
                context.Comments.InsertOnSubmit(comment);
                context.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
                throw new FaultException(ex.Message);

            }
        }

        #endregion

        #region getMax_CommentID


        public int getMax_CommentID()
        {
            var q = (from c in context.Comments
                     select (int?) c.CommentID).Max() ?? 0;
            return q;
        }

        #endregion
    }
}

